<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>AMBHAS: /home/tomer/svn/ambhas/ambhas/easy_gw_1d.py Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AMBHAS
   
   </div>
   
  </td>
  
  
  
   
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('easy__gw__1d_8py.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">easy_gw_1d.py</div>  </div>
</div><!--header-->
<div class="contents">
<a href="easy__gw__1d_8py.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a><a class="code" href="namespaceambhas_1_1easy__gw__1d.html">00001</a> <span class="comment"># -*- coding: utf-8 -*-</span>
<a name="l00002"></a>00002 <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00003"></a>00003 <span class="stringliteral">Created on Wed Jan 25 13:30:46 2012</span>
<a name="l00004"></a>00004 <span class="stringliteral"></span>
<a name="l00005"></a>00005 <span class="stringliteral">@author: Sat Kumar Tomer</span>
<a name="l00006"></a>00006 <span class="stringliteral">@website: www.ambhas.com</span>
<a name="l00007"></a>00007 <span class="stringliteral">@email: satkumartomer@gmail.com</span>
<a name="l00008"></a>00008 <span class="stringliteral"></span>
<a name="l00009"></a>00009 <span class="stringliteral">this module reads the data from xls file</span>
<a name="l00010"></a>00010 <span class="stringliteral">perform the lumped grounwater level modelling</span>
<a name="l00011"></a>00011 <span class="stringliteral">then save the output as xls file and images</span>
<a name="l00012"></a>00012 <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 <span class="keyword">import</span> numpy <span class="keyword">as</span> np
<a name="l00015"></a>00015 <span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt
<a name="l00016"></a>00016 <span class="keyword">import</span> xlrd, xlwt
<a name="l00017"></a>00017 <span class="keyword">from</span> ambhas.gw <span class="keyword">import</span> GW_1D
<a name="l00018"></a>00018 <span class="keyword">import</span> scikits.timeseries <span class="keyword">as</span> ts
<a name="l00019"></a>00019 <span class="keyword">import</span> scikits.timeseries.lib.plotlib <span class="keyword">as</span> tpl
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 
<a name="l00022"></a><a class="code" href="namespaceambhas_1_1easy__gw__1d.html#af434899dde0c02444889845a29a97a01">00022</a> <span class="keyword">def </span><a class="code" href="namespaceambhas_1_1easy__gw__1d.html#af434899dde0c02444889845a29a97a01">gw_model_file</a>(in_fname, out_fname, figure_dir=None):
<a name="l00023"></a>00023     <span class="stringliteral">&quot;&quot;&quot;&quot;</span>
<a name="l00024"></a>00024 <span class="stringliteral">    input:</span>
<a name="l00025"></a>00025 <span class="stringliteral">        in_fname:   name of input xls file</span>
<a name="l00026"></a>00026 <span class="stringliteral">        out_fname:  name of the output xls file</span>
<a name="l00027"></a>00027 <span class="stringliteral">        figure_dir: name of the directory where to save the out figures</span>
<a name="l00028"></a>00028 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030     <span class="comment"># read the data from xls file</span>
<a name="l00031"></a>00031     in_book = xlrd.open_workbook(in_fname)
<a name="l00032"></a>00032     sheet_names = in_book.sheet_names()
<a name="l00033"></a>00033     sheet_names.remove(<span class="stringliteral">&#39;legend&#39;</span>)
<a name="l00034"></a>00034     
<a name="l00035"></a>00035     out_book = xlwt.Workbook()
<a name="l00036"></a>00036     <span class="keywordflow">for</span> sheet_name <span class="keywordflow">in</span> sheet_names:
<a name="l00037"></a>00037     
<a name="l00038"></a>00038         sheet = in_book.sheet_by_name(sheet_name)
<a name="l00039"></a>00039         <span class="comment"># read the input for one well</span>
<a name="l00040"></a>00040         t = sheet.nrows-1
<a name="l00041"></a>00041         year = np.empty(t, <span class="stringliteral">&#39;int&#39;</span>)
<a name="l00042"></a>00042         month = np.empty(t, <span class="stringliteral">&#39;int&#39;</span>)
<a name="l00043"></a>00043         rainfall = np.empty(t)
<a name="l00044"></a>00044         pumping = np.empty(t)
<a name="l00045"></a>00045         meas_gwl = np.empty(t)
<a name="l00046"></a>00046         r = np.empty(t)
<a name="l00047"></a>00047         <span class="keywordflow">for</span> i <span class="keywordflow">in</span> range(t):
<a name="l00048"></a>00048             year[i] = sheet.cell_value(i+1,0)
<a name="l00049"></a>00049             month[i] = sheet.cell_value(i+1,1)
<a name="l00050"></a>00050             rainfall[i] = sheet.cell_value(i+1,2)
<a name="l00051"></a>00051             pumping[i] = sheet.cell_value(i+1,3)
<a name="l00052"></a>00052             meas_gwl[i] = sheet.cell_value(i+1,4)
<a name="l00053"></a>00053             r[i] = sheet.cell_value(i+1,5)
<a name="l00054"></a>00054         F = sheet.cell_value(1,6)
<a name="l00055"></a>00055         G = sheet.cell_value(1,7)
<a name="l00056"></a>00056         hmin = sheet.cell_value(1,8)
<a name="l00057"></a>00057         
<a name="l00058"></a>00058         <span class="comment"># run the model</span>
<a name="l00059"></a>00059         gw_model = <a class="code" href="classambhas_1_1gw_1_1GW__1D.html">GW_1D</a>(rainfall, pumping)
<a name="l00060"></a>00060         gw_model.set_parameters(F, G, r, hmin)
<a name="l00061"></a>00061         
<a name="l00062"></a>00062         hini = meas_gwl[0]
<a name="l00063"></a>00063         gw_model.run_model(hini,t)
<a name="l00064"></a>00064         sim_gwl = gw_model.h
<a name="l00065"></a>00065         lam = gw_model.lam
<a name="l00066"></a>00066         sy = gw_model.sy
<a name="l00067"></a>00067         discharge = gw_model.discharge
<a name="l00068"></a>00068         
<a name="l00069"></a>00069         <span class="comment">#write the output</span>
<a name="l00070"></a>00070         sheet = out_book.add_sheet(sheet_name)
<a name="l00071"></a>00071         sheet.write(0,0,<span class="stringliteral">&#39;year&#39;</span>)
<a name="l00072"></a>00072         sheet.write(0,1,<span class="stringliteral">&#39;month&#39;</span>)
<a name="l00073"></a>00073         sheet.write(0,2,<span class="stringliteral">&#39;rainfall&#39;</span>)
<a name="l00074"></a>00074         sheet.write(0,3,<span class="stringliteral">&#39;pumping&#39;</span>)
<a name="l00075"></a>00075         sheet.write(0,4,<span class="stringliteral">&#39;measured gwl&#39;</span>)
<a name="l00076"></a>00076         sheet.write(0,5,<span class="stringliteral">&#39;simulated gwl&#39;</span>)
<a name="l00077"></a>00077         sheet.write(0,6,<span class="stringliteral">&#39;recharge&#39;</span>)
<a name="l00078"></a>00078         sheet.write(0,7,<span class="stringliteral">&#39;discharge&#39;</span>)
<a name="l00079"></a>00079         sheet.write(0,8,<span class="stringliteral">&#39;lambda&#39;</span>)
<a name="l00080"></a>00080         sheet.write(0,9,<span class="stringliteral">&#39;sy&#39;</span>)
<a name="l00081"></a>00081         <span class="keywordflow">for</span> i <span class="keywordflow">in</span> range(t):
<a name="l00082"></a>00082             sheet.write(i+1,0,year[i])
<a name="l00083"></a>00083             sheet.write(i+1,1,month[i])
<a name="l00084"></a>00084             sheet.write(i+1,2,rainfall[i])
<a name="l00085"></a>00085             sheet.write(i+1,3,pumping[i])
<a name="l00086"></a>00086             sheet.write(i+1,4,meas_gwl[i])
<a name="l00087"></a>00087             sheet.write(i+1,5,sim_gwl[i])
<a name="l00088"></a>00088             sheet.write(i+1,6,rainfall[i]*r[i])
<a name="l00089"></a>00089             sheet.write(i+1,7,discharge[i])
<a name="l00090"></a>00090         sheet.write(1,8,lam)
<a name="l00091"></a>00091         sheet.write(1,9,sy)
<a name="l00092"></a>00092             
<a name="l00093"></a>00093         first_date = ts.Date(freq=<span class="stringliteral">&#39;M&#39;</span>,year=year[0],month=month[1])
<a name="l00094"></a>00094         gw_meas_series = ts.time_series(meas_gwl, start_date=first_date)
<a name="l00095"></a>00095         gw_sim_series = ts.time_series(sim_gwl, start_date=first_date)
<a name="l00096"></a>00096         
<a name="l00097"></a>00097         <span class="keywordflow">if</span> figure_dir <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>:
<a name="l00098"></a>00098             <span class="comment"># save the figure</span>
<a name="l00099"></a>00099             fig = tpl.tsfigure()
<a name="l00100"></a>00100             fsp = fig.add_tsplot(111)
<a name="l00101"></a>00101             fsp.tsplot(gw_meas_series, <span class="stringliteral">&#39;</span><span class="stringliteral">r&#39;, lw=3, label=&#39;</span>measured&#39;)
<a name="l00102"></a>00102             fsp.tsplot(gw_sim_series, <span class="stringliteral">&#39;g&#39;</span>, lw=3, label=<span class="stringliteral">&#39;simulated&#39;</span>)
<a name="l00103"></a>00103             fsp.legend(loc=<span class="stringliteral">&#39;best&#39;</span>)
<a name="l00104"></a>00104             plt.ylabel(<span class="stringliteral">&#39;Groundwater Level&#39;</span> )
<a name="l00105"></a>00105             plt.savefig(figure_dir+<span class="stringliteral">&#39;%s.png&#39;</span>%sheet_name)
<a name="l00106"></a>00106             plt.close()
<a name="l00107"></a>00107         
<a name="l00108"></a>00108         print(<span class="stringliteral">&#39;%s completed succesfully&#39;</span>%sheet_name)
<a name="l00109"></a>00109     
<a name="l00110"></a>00110     <span class="comment"># save the xls file</span>
<a name="l00111"></a>00111     out_book.save(out_fname)
</pre></div></div><!-- contents -->
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="easy__gw__1d_8py.html">easy_gw_1d.py</a>      </li>

    <li class="footer">Generated on Sat Jul 21 2012 12:26:08 for AMBHAS by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
